package com.wxxymaker.edu.controller;

import com.blade.ioc.annotation.Inject;
import com.blade.mvc.annotation.Path;
import com.blade.mvc.annotation.PathParam;
import com.blade.mvc.annotation.PostRoute;
import com.blade.mvc.ui.RestResponse;
import com.wxxymaker.edu.model.entity.PracticeOption;
import com.wxxymaker.edu.service.PracticeOptionService;

/**
 * @AUTHOR soft
 * @DATE 2018/10/14 2:53
 * @DESCRIBE
 */
@Path(value = "/course/set/praOption", restful = true)
public class PracticeOptionHandler {

    @Inject
    private PracticeOptionService practiceOptionService;

    @PostRoute("/:kid/add")
    public RestResponse add(PracticeOption practiceOption) {
        if (practiceOption.getPracticeId()>0) {
            PracticeOption add = practiceOptionService.add(practiceOption);
            if (add!=null){
                return RestResponse.ok(add);
            }
        }
        return RestResponse.fail();
    }

    @PostRoute("/:kid/change")
    public RestResponse change(PracticeOption practiceOption) {
        Integer id = practiceOption.getId();
        if (practiceOptionService.change(practiceOption)) {
            practiceOption.setId(id);
            return RestResponse.ok(practiceOption);
        }
        return RestResponse.fail();
    }

    @PostRoute("/:kid/delete/:id")
    public RestResponse delete_(@PathParam Integer id) {
        PracticeOption delete = practiceOptionService.delete(id);
        if (delete != null) {
            return RestResponse.ok(delete);
        }
        return RestResponse.fail();
    }
}
